import messageUtil from "../utils/messageUtil"
import commonData from "./data"
import httpUtil from "../utils/httpUtil"
import logApi from "../api/logApi"

function getAuthorizeMobile(encryptedData, sign, successHandler, errHandler) {
  let params = {
    appid: commonData.getAppid(),
    encryptedData: encryptedData,
    sign: sign,
  }
  logApi.addKeepLog('自动获取手机号解密发送前，参数：' + JSON.stringify(params))
  httpUtil.post("/api/rf/openSignCj", params, res => {
    logApi.addKeepLog('自动获取手机号解密返回，参数：' + JSON.stringify(params) + '。返回：' + JSON.stringify(res))
    if (successHandler) {
      console.log('getAuthorizeMobile', res.data)
      successHandler(res.data)
    }

  }, err => {
    logApi.addKeepLog('自动获取手机号解密错误，参数：' + JSON.stringify(params) + '。错误信息：' + JSON.stringify(err))
    if (errHandler) {
      errHandler(err)
    }
  })
}
function getYys (mobile, successCallBack, errorCallBack) {
	httpUtil.postReturnSource('/api/jssxk/getYys', {
		mobile
	}, res => {
		// {"code": 0,"reason": "Succ","result": {"Mobile": "13880104834","Province": "四川","City": "成都","Isp": "中国移动"}}
		console.log('getOperator', res)
		if (res.reason != 'Succ' || res.code != 0) {
			messageUtil.showFail('获取运营商失败，请于管理员联系')
			return;
		}
		successCallBack(res.result);
	}, err => {
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}

module.exports = {
  getAuthorizeMobile: getAuthorizeMobile,
  getYys:getYys
}